package com.zqweb.gulimall.essearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ESClientConfig {
    // 声明请求ES的对象选项配置
    public static RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        /**
         * 可以通过builder对请求ES的对象进行相关的OPTIONS配置。后续根据需要设置
         */
        COMMON_OPTIONS = builder.build();
    }

    @Bean
    // 创建连接指定ES服务器的RestHighLevelClient对象，并注入到容器中
    public RestHighLevelClient client(){
        // scheme协议，默认为http
        RestClientBuilder builder = RestClient.builder(
                new HttpHost("192.168.137.40",9200,"http")
        );
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        return restHighLevelClient;
    }
}
